package com.cykj.admin.service.impl;

import com.cykj.admin.mapper.IndustryMapper;
import com.cykj.admin.service.IIndustryService;
import com.cykj.admin.vo.IndustryVO;
import com.cykj.common.dto.ResponseDTO;
import com.cykj.common.entity.CompanyCheckDO;
import com.cykj.common.entity.IndustryDO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.admin.service.impl
 * @Author: 小小卢
 * @CreateTime: 2025-08-20 16:08
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class IndustryServiceImpl implements IIndustryService {

    @Autowired
    private IndustryMapper industryMapper;

    /**
    * @Description: 查询行业
    * @Param: [industryVO]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO selectIndustry(IndustryVO industryVO) {
        PageInfo<IndustryDO> page;
        //开启分页
        PageHelper.startPage(industryVO.getCurrentPage(),industryVO.getPageSize());

        List<IndustryDO> list = industryMapper.selectIndustry(industryVO);

        page = new PageInfo<>(list);

        if (page.getTotal() < page.getPageSize() && list.size() == 0 && page.getTotal() != 0 ){
            industryVO.setCurrentPage(1);
            PageHelper.startPage(industryVO.getCurrentPage(),industryVO.getPageSize());
            List<IndustryDO> list2 = industryMapper.selectIndustry(industryVO);
            page = new PageInfo<>(list2);
        }

        return ResponseDTO.success(page);
    }

    /**
    * @Description: 新增行业
    * @Param: [industryVO]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO addIndustry(IndustryVO industryVO) {
        Integer row = industryMapper.addIndustry(industryVO);
        if (row > 0){
            return ResponseDTO.success(row);
        }
        return ResponseDTO.error("新增失败");
    }

    /**
    * @Description: 修改行业
    * @Param: [industryVO]
    * @return: com.cykj.common.dto.ResponseDTO
    */
    @Override
    public ResponseDTO updateIndustry(IndustryVO industryVO) {
        Integer row = industryMapper.updateIndustry(industryVO);
        if (row > 0){
            return ResponseDTO.success(row);
        }
        return ResponseDTO.error("修改失败");
    }
}